package com.hancher.api;

import com.hancher.common.androidutil.ApkInfoUtil;
import com.hancher.common.androidutil.AsyncUtils;
import com.hancher.common.net.NetUtil;
import com.hancher.common.net.bean.ResultBean;

import java.io.Serializable;

import io.reactivex.rxjava3.core.Observable;
import retrofit2.http.Field;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.POST;

/**
 * 作者: Hancher
 * 日期: 2020/9/6 10:21
 * 描述: 蒲公英接口
 */
public class PgyerApi {
    public static String HOST_PGYER = "https://www.pgyer.com/";
    static String HOST_PGYER_APIKEY = "80ad50364f73176d9ec65c70793f2da0";
    static String HOST_PGYER_APPKEY = "33d46ffbc79c6eb2b15aa74c4a598061";
    public static HancherService service = new NetUtil<>(HancherService.class).setBaseUrl(HOST_PGYER).build();

    public static Observable<ResultBean<LastestApkBean>> getLastest() {
        return service.getLastest(HOST_PGYER_APIKEY, HOST_PGYER_APPKEY, ApkInfoUtil.getVersionCode())
                .compose(AsyncUtils.getThreadTransformer());
    }

    interface HancherService {

        @POST("apiv2/app/check")
        @FormUrlEncoded
        Observable<ResultBean<LastestApkBean>> getLastest(@Field("_api_key") String apiKey,
                                                          @Field("appKey") String appKey,
                                                          @Field("buildVersion") long buildVersion);

    }

    public static class LastestApkBean implements Serializable {

        private String buildBuildVersion;
        private String forceUpdateVersion;
        private String forceUpdateVersionNo;
        private boolean needForceUpdate;
        private String downloadURL;
        private boolean buildHaveNewVersion;
        private String buildVersionNo;
        private String buildVersion;
        private String buildUpdateDescription;
        private String buildDescription;
        private String appKey;
        private String buildKey;
        private String buildName;
        private String buildIcon;
        private String buildFileKey;
        private String buildFileSize;

        public boolean isNeedForceUpdate() {
            return needForceUpdate;
        }

        public boolean isBuildHaveNewVersion() {
            return buildHaveNewVersion;
        }

        public String getBuildDescription() {
            return buildDescription;
        }

        public LastestApkBean setBuildDescription(String buildDescription) {
            this.buildDescription = buildDescription;
            return this;
        }

        public void setBuildBuildVersion(String buildBuildVersion) {
            this.buildBuildVersion = buildBuildVersion;
        }

        public String getBuildBuildVersion() {
            return buildBuildVersion;
        }

        public void setForceUpdateVersion(String forceUpdateVersion) {
            this.forceUpdateVersion = forceUpdateVersion;
        }

        public String getForceUpdateVersion() {
            return forceUpdateVersion;
        }

        public void setForceUpdateVersionNo(String forceUpdateVersionNo) {
            this.forceUpdateVersionNo = forceUpdateVersionNo;
        }

        public String getForceUpdateVersionNo() {
            return forceUpdateVersionNo;
        }

        public void setNeedForceUpdate(boolean needForceUpdate) {
            this.needForceUpdate = needForceUpdate;
        }

        public boolean getNeedForceUpdate() {
            return needForceUpdate;
        }

        public void setDownloadURL(String downloadURL) {
            this.downloadURL = downloadURL;
        }

        public String getDownloadURL() {
            return downloadURL;
        }

        public void setBuildHaveNewVersion(boolean buildHaveNewVersion) {
            this.buildHaveNewVersion = buildHaveNewVersion;
        }

        public boolean getBuildHaveNewVersion() {
            return buildHaveNewVersion;
        }

        public void setBuildVersionNo(String buildVersionNo) {
            this.buildVersionNo = buildVersionNo;
        }

        public String getBuildVersionNo() {
            return buildVersionNo;
        }

        public void setBuildVersion(String buildVersion) {
            this.buildVersion = buildVersion;
        }

        public String getBuildVersion() {
            return buildVersion;
        }

        public void setBuildUpdateDescription(String buildUpdateDescription) {
            this.buildUpdateDescription = buildUpdateDescription;
        }

        public String getBuildUpdateDescription() {
            return buildUpdateDescription;
        }

        public void setAppKey(String appKey) {
            this.appKey = appKey;
        }

        public String getAppKey() {
            return appKey;
        }

        public void setBuildKey(String buildKey) {
            this.buildKey = buildKey;
        }

        public String getBuildKey() {
            return buildKey;
        }

        public void setBuildName(String buildName) {
            this.buildName = buildName;
        }

        public String getBuildName() {
            return buildName;
        }

        public void setBuildIcon(String buildIcon) {
            this.buildIcon = buildIcon;
        }

        public String getBuildIcon() {
            return buildIcon;
        }

        public void setBuildFileKey(String buildFileKey) {
            this.buildFileKey = buildFileKey;
        }

        public String getBuildFileKey() {
            return buildFileKey;
        }

        public void setBuildFileSize(String buildFileSize) {
            this.buildFileSize = buildFileSize;
        }

        public String getBuildFileSize() {
            return buildFileSize;
        }

        @Override
        public String toString() {
            return "LastestApkBean{" +
                    "buildBuildVersion='" + buildBuildVersion + '\'' +
                    ", forceUpdateVersion='" + forceUpdateVersion + '\'' +
                    ", forceUpdateVersionNo='" + forceUpdateVersionNo + '\'' +
                    ", needForceUpdate=" + needForceUpdate +
                    ", downloadURL='" + downloadURL + '\'' +
                    ", buildHaveNewVersion=" + buildHaveNewVersion +
                    ", buildVersionNo='" + buildVersionNo + '\'' +
                    ", buildVersion='" + buildVersion + '\'' +
                    ", buildUpdateDescription='" + buildUpdateDescription + '\'' +
                    ", appKey='" + appKey + '\'' +
                    ", buildKey='" + buildKey + '\'' +
                    ", buildName='" + buildName + '\'' +
                    ", buildIcon='" + buildIcon + '\'' +
                    ", buildFileKey='" + buildFileKey + '\'' +
                    ", buildFileSize='" + buildFileSize + '\'' +
                    '}';
        }
    }
}